<template>
  <div class="settle">
    <!-- 导航栏 -->
    <van-nav-bar
  title="商家入驻"
  left-arrow
  @click="back"
/>
  <!-- 表单组 -->
  <van-cell-group inset>
  <!-- 上传图片 -->
  <input type="file" @change="filechange" class="in1">
  <!-- 显示图片 -->
  <img :src="imgd" alt="" class="im1">
  </van-cell-group>
  <!-- 城市输入框 -->
  <van-cell-group inset>
  <van-field v-model="city" label="城市:" placeholder="请输入城市名称" />
  </van-cell-group>
  <!-- 详细科室输入框 -->
  <van-cell-group inset>
  <van-field v-model="administrativeOffice" label="详细科室:" placeholder="请输入详细科室" />
  </van-cell-group>
  <!-- 药店级别输入框 -->
  <van-cell-group inset>
  <van-field v-model="state" label="级别:" placeholder="请输入药店级别" />
  </van-cell-group>
  <!-- 姓名输入框 -->
  <van-cell-group inset>
  <van-field v-model="name" label="名字:" placeholder="请输入姓名" />
  </van-cell-group>
  <!-- 毕业学校输入框 -->
  <van-cell-group inset>
  <van-field v-model="nosocomium" label="毕业学校:" placeholder="请输入毕业学校" />
  </van-cell-group>
  <!-- 主科室输入框 -->
  <van-cell-group inset>
  <van-field v-model="department" label="主科室:" placeholder="请输入主科室名称" />
  </van-cell-group>
  <!-- 证件信息输入框 -->
  <van-cell-group inset>
  <van-field v-model="identitycard" label="证件信息:" placeholder="请输入身份证号" />
  </van-cell-group>
  <!-- 提交按钮 -->
  <button class="sub" @click="go">提交入驻申请</button>
  <!-- 查看审核情况按钮 -->
  <button class="look" @click="look()">查看审核情况</button>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import instance from '../axios/index';
import { showToast,showSuccessToast,showFailToast } from 'vant';
// 城市输入框
const city = ref('')
// 详细科室输入框
const administrativeOffice = ref('')
// 药店级别输入框
const state = ref('')
// 姓名输入框
const name = ref('')
// 毕业学校输入框
const nosocomium = ref('')
// 主科室输入框
const department = ref('')
// 证件信息输入框
const identitycard = ref('')
// 路由
const router= useRouter()

// 图片地址
const imgd=ref('')
// 上传图片
const filechange = (e) => {
  const file = e.target.files[0];
  if(file){
    const formData=new FormData();
    formData.append('file',file);
    instance.post('/api/addimg',formData).then((res)=>{
      imgd.value=res.data.url
    })
  }
}
// 返回上一页
const back = () => {
  router.go(-1);
}

// 提交入驻申请
const go = () => {
  if (!city.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  if (!administrativeOffice.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  if (!state.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  if (!name.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  if (!nosocomium.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  if (!department.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  if (!identitycard.value) {
    showToast('输入内容不能为空，请填写完整');
    return;
  }
  const data={
  city:city.value,
  administrativeOffice:administrativeOffice.value,
  state:state.value,
  name:name.value,
  nosocomium:nosocomium.value,
  department:department.value,
  img:imgd.value,
  identitycard:identitycard.value
  }
  instance.post('/api/doctorauditadd',data).then((res)=>{
    if(res.data.code==200){
      const subid=res.data.data.data.id
      showSuccessToast('提交成功');
      localStorage.setItem('subid',subid)
  }else{
    showFailToast('提交失败，名字重复');
  }
  })
}
// 查看审核结果
  const look=()=>{
    instance.post('/api/doctorauditresult',{ id:localStorage.getItem('subid')  }).then(res=>{
        showSuccessToast(res.data.data[0].flag);
    })
  }
</script>

<style scoped>
.settle {
  width: 100%;
  height: 5rem;
  position: relative;
}
.van-cell-group{
  margin-top: .1rem;
}
.sub{
  width: 1.5rem;
  height: .4rem;
  background: blue;
  color: #fff;
  border: none;
  border-radius: .1rem;
  margin-left: 1rem;
  margin-top: .2rem
}
.look{
  width: 1.5rem;
  height: .4rem;
  background: orange;
  color: #fff;
  border: none;
  border-radius: .1rem;
  margin-left: 1rem;
  margin-top: .1rem
}
.van-uploader{
  margin-left: 1.3rem;
}
.im1{
  width: .8rem;
  height: .8rem;
  border-radius: 50%;
  margin-left: 1.3rem;
}
.in1{
  width: 1rem;
  position: absolute;
  top: .8rem;
  left: 1.3rem;
  opacity: 0;
}
</style>